package org.sunspotworld.robowulf;

import com.sun.spot.peripheral.IDriver;
import com.sun.spot.peripheral.Spot;
import com.sun.spot.sensorboard.io.IOutputPin;
import com.sun.spot.sensorboard.peripheral.Servo;

public class RobowulfServo extends Servo implements IDriver {
	public RobowulfServo(IOutputPin pin) {
		super(pin);
		Spot.getInstance().getDriverRegistry().add(this);
	}
	
	public void destroy() {
		Spot.getInstance().getDriverRegistry().remove(this);
	}
	
	public void forward(float power) {
		setPosition(0.5F + power*0.5F);
	}
	
	public void forward() {
		forward(1F);
	}

	public void backward(float power) {
		setPosition(0.5F - power*0.5F);
	}
	
	public void backward() {
		backward(1F);
	}

	public void brake() {
		setPosition(0.5F);
	}
	
	public void floatServo() {
		setValue(0);
	}
	
	public void calibrate(int center, int fullForwardOffset) {
		setBounds(center - fullForwardOffset, center + fullForwardOffset);
	}

	// IDriver
	public String getDriverName() { return "Robowulf Servo"; }
	public void setUp() {}
	public void shutDown() {}
	public boolean tearDown() {	return getValue() == 0; }
}
